import axios from "axios";
import {globalStore} from "@/assets/store-index.js";

axios.defaults.baseURL = "/api"


axios.interceptors.request.use((request)=>{
    const gs = globalStore()
    const token = gs.token;
    if (token){
        request.headers.token = token;
    }
    return request;
})

axios.interceptors.response.use((response)=> {
    const resultBean = response.data;
    if (resultBean.code == 500) {
        return Promise.reject(resultBean.message);
    }
    return response.data;
}, (error) => {
    return Promise.reject(error.message);
})